package com.ruoyi.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.domain.TBaseCost;
import com.ruoyi.system.mapper.TBaseCostMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TBaseBankMapper;
import com.ruoyi.system.domain.TBaseBank;
import com.ruoyi.system.service.ITBaseBankService;

/**
 * 银行Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-21
 */
@Service
public class TBaseBankServiceImpl  extends ServiceImpl<TBaseBankMapper, TBaseBank> implements ITBaseBankService
{
    @Autowired
    private TBaseBankMapper tBaseBankMapper;

    /**
     * 查询银行
     * 
     * @param bankId 银行主键
     * @return 银行
     */
    @Override
    public TBaseBank selectTBaseBankByBankId(Long bankId)
    {
        return tBaseBankMapper.selectTBaseBankByBankId(bankId);
    }

    /**
     * 查询银行列表
     * 
     * @param tBaseBank 银行
     * @return 银行
     */
    @Override
    public List<TBaseBank> selectTBaseBankList(TBaseBank tBaseBank)
    {
        return tBaseBankMapper.selectTBaseBankList(tBaseBank);
    }

    /**
     * 新增银行
     * 
     * @param tBaseBank 银行
     * @return 结果
     */
    @Override
    public int insertTBaseBank(TBaseBank tBaseBank)
    {
        Long count = tBaseBankMapper.selectCount(new LambdaQueryWrapper<TBaseBank>().eq(TBaseBank::getBankName, tBaseBank.getBankName()));
        if(count > 0){
            throw new RuntimeException("银行名称【"+tBaseBank.getBankName() + "】已经存在");
        }
        return tBaseBankMapper.insertTBaseBank(tBaseBank);
    }

    /**
     * 修改银行
     * 
     * @param tBaseBank 银行
     * @return 结果
     */
    @Override
    public int updateTBaseBank(TBaseBank tBaseBank)
    {
        Long count = tBaseBankMapper.selectCount(new LambdaQueryWrapper<TBaseBank>().eq(TBaseBank::getBankName, tBaseBank.getBankName()));
        if(count > 1){
            throw new RuntimeException("银行名称【"+tBaseBank.getBankName() + "】已经存在");
        }
        return tBaseBankMapper.updateTBaseBank(tBaseBank);
    }

    /**
     * 批量删除银行
     * 
     * @param bankIds 需要删除的银行主键
     * @return 结果
     */
    @Override
    public int deleteTBaseBankByBankIds(Long[] bankIds)
    {
        return tBaseBankMapper.deleteTBaseBankByBankIds(bankIds);
    }

    /**
     * 删除银行信息
     * 
     * @param bankId 银行主键
     * @return 结果
     */
    @Override
    public int deleteTBaseBankByBankId(Long bankId)
    {
        return tBaseBankMapper.deleteTBaseBankByBankId(bankId);
    }
}
